package com.app.controller;


import com.app.entity.Subject;
import com.app.entity.User;
import com.app.service.SubjectService;
import com.app.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jt
 * @since 2021-04-07
 */
@RestController
@RequestMapping("/subject")
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    /**
     * 查询用户关联教练发布的课程
     *
     * @return
     */
    @RequestMapping("/token/findSubject")
    public Result findSubject(@RequestParam("newdate") String newdate) {

        return subjectService.findSubject(newdate);
    }

    /**
     * 获取时间
     */
    @RequestMapping("/findNewTime")
    public Result findNewTime() {
        List list = new ArrayList(3);
        LocalDateTime now = LocalDateTime.now();
        String newtime = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        list.add(newtime);
        String houtime = now.plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        list.add(houtime);
        return Result.success(list);
    }

    /**
     * 查询计划
     */
    @RequestMapping("/token/findSubjectByTime")
    public Result findSubjectByTime(@RequestParam("time") String time) {
        return subjectService.findSubjectByTime(time);
    }

    /**
     * 教练发布计划
     */
    @RequestMapping("/token/addSubjectByCoach")
    public Result addSubjectByCoach(@RequestBody Subject subject) {
        return subjectService.addSubjectByCoach(subject);
    }

    /**
     * 教练查看预约状态
     */
    @RequestMapping("/token/findSubjectSatate")
    public Result findSubjectSatate(@RequestParam("newdate") String newdate) {
        System.out.println(newdate);
        return subjectService.findSubjectSatate(newdate);
    }

    /**
     * 学员预约
     */
    @RequestMapping("/token/orderSubjectByStudent")
    public Result orderSubjectByStudent(@RequestParam("id") Integer id) {
        return subjectService.orderSubjectByStudent(id);
    }

    /**
     * 查询用户申请
     */
    @RequestMapping("/token/findUserShenQingByAdmin")
    public Result orderSubjectByStudent() {
        return subjectService.findUserShenQingByAdmin();
    }

    /**
     * 用户考试申请通过
     */
    @RequestMapping("/token/UserPassShenQingByAdmin")
    public Result UserPassShenQingByAdmin(@RequestBody User user) {
        return subjectService.UserPassShenQingByAdmin(user);
    }
}

